package de.urlaub.server.comm;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.interceptor.Interceptors;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import de.urlaub.client.VacationClient;
import de.urlaub.server.logging.LoggingInterceptor;

@MessageDriven(activationConfig = {
		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
		@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/DLQ") })
@Interceptors(LoggingInterceptor.class)
public class MDBReceiver implements MessageListener 
{
	public MDBReceiver() 
	{
	}

	public final void onMessage(Message msg) 
	{
		try 
		{
			TextMessage textMessage = (TextMessage) msg;
			String employeeId = textMessage.getText().substring(0, textMessage.getText().indexOf(';'));
			String message = textMessage.getText().substring(textMessage.getText().indexOf(';') + 1);
			VacationClient.showMessageDialog(employeeId, message);
		} 
		catch (Throwable th) 
		{
			th.printStackTrace();
		}
	}

}
